package com.igeek;

import com.igeek.dao.EmpDao;
import com.igeek.dao.UserDao;
import com.igeek.entity.Employee;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.util.List;

public class Demo4 {

    public static void main(String[] args) throws  Exception{
        //读取配置文件的输入流
        Reader reader = Resources.getResourceAsReader("mybatis.xml");
        //创建builder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        //构建sessionFactory
        SqlSessionFactory factory = builder.build(reader);
        //打开session
        SqlSession session = factory.openSession();

        EmpDao empDao = session.getMapper(EmpDao.class);
//        List<Employee> list = empDao.findBySalary(null, 9000.0);
//        for (Employee employee : list) {
//            System.out.println(employee.getEmpName()+"\t"+employee.getSalary());
//        }

//        List<Employee> list = empDao.findByJob("ST_MAN");
//        for (Employee emp : list) {
//            System.out.println(emp.getEmpName()+"\t"+emp.getJob()+"\t"+emp.getSalary()+"\t"+emp.getPhoneNumber());
//        }


        UserDao userDao = session.getMapper(UserDao.class);
        userDao.deleteById(new int[]{1,2,3,5});

        session.close();
    }
}
